/*
 * @lc app=leetcode.cn id=500 lang=csharp
 *
 * [500] 键盘行
 */

// @lc code=start
public class Solution {
    public string[] FindWords(string[] words) {
        string[] rows = new string[]{"qwertyuiop", "asdfghjkl", "zxcvbnm"};
        List<string> result = new List<string>();
        foreach (var word in words)
        {
            int row = -1;
            foreach (var c in word)
            {
                if (row == -1)
                {
                    foreach (var r in rows)
                    {
                        if (r.Contains(char.ToLower(c)))
                        {
                            row = Array.IndexOf(rows, r);
                            break;
                        }
                    }
                }
                else
                {
                    if (!rows[row].Contains(char.ToLower(c)))
                    {
                        row = -1;
                        break;
                    }
                }
            }
            if (row != -1)
            {
                result.Add(word);
            }
        }
        return result.ToArray();
    
    }
}
// @lc code=end

